struct ListNode* reverse(struct ListNode* head)
{
    struct ListNode* n1 = NULL;
    struct ListNode* n2 = head;
    struct ListNode* n3 = NULL;
    if (n2)
        n3 = n2->next;

    while (n2)
    {
        n2->next = n1;
        n1 = n2;
        n2 = n3;
        if (n3)
            n3 = n3->next;
    }

    return n1;
}

struct ListNode* doubleIt(struct ListNode* head)
{
    struct ListNode* prev = NULL;
    struct ListNode* Back = reverse(head);

    head = Back;
    int add = 0;

    while (Back)
    {
        int temp = Back->val * 2 + add;
        add = temp / 10;

        prev = Back;

        Back->val = temp % 10;
        Back = Back->next;
    }

    if (add > 0)
    {
        struct ListNode* newnode = malloc(sizeof(struct ListNode));
        newnode->val = add;
        newnode->next = NULL;

        prev->next = newnode;
    }

    head = reverse(head);
    return head;
}